<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title th:text="${testMsg}">Insert title here</title>
</head>
<body>
<h1 th:text="${testMsg}">Test</h1>
<h1 class="test">456465465</h1>
<a><h1 th:text="'项目根路径：'+${HY_DOMAIN}">456465465</h1></a>
<a th:href="@{/transactional}"><h1>事务测试</h1></a>
<a th:href="@{/transactionals}"><h1>事务嵌套测试</h1></a>
<a th:href="@{/admin/}"><h1>AngularJS 主页</h1></a>
<a th:href="@{/layout/index1.html}"><h1>layout主页1</h1></a>
<a th:href="@{/layout/index2.html}"><h1>layout主页2</h1></a>
<button id="exportWord">导出Word Demo</button>
<button id="exportExcel">导出Excel Demo</button>
<div>
    <label>save word</label>
    <div>
        <input type="file" id="word">
        <button type="button" id="wordUpload">点击上传</button>
    </div>
    <button type="button" id="getWord">点击获取</button>
</div>
<div>
    <label>File input</label>
    <div>
        <input type="file" id="file">
        <button type="button" id="upload">点击上传</button>
    </div>
</div>
<div>
    <label>Files input</label>
    <div>
        <input type="file" id="files" multiple>
        <button type="button" id="uploads">点击上传</button>
    </div>
</div>
<ul>
    <!--/*@thymesVar id="enum" type="cn.example.util.enumerate.ResultCode[]"*/-->
    <li th:each="c:${enum}" th:text="${c.code+c.name()}"></li>
</ul>
<script th:src="@{/vendor/jquery/jquery-1.12.4.min.js}"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var _url = [[${HY_DOMAIN}]];
    $(function () {

        $('#exportWord').bind('click', function () {
            var url = _url + "/exportWord";
            window.open(url);
        });

        $('#exportExcel').bind('click', function () {
            var url = _url + "/exportExcel";
            window.open(url);
        });

        $('#getWord').bind('click', function () {
            var url = _url + "/getWord";
            window.open(url);
        });

        $('#wordUpload').bind('click', function () {
            var formData = new FormData();
            formData.append('word', $('#word')[0].files[0]);
            formData.append('name', "test");
//            console.log($('#file')[0].files[0].size);//文件大小
            upload(_url + "/saveWord", formData);
        });

        $('#upload').bind('click', function () {
            var formData = new FormData();
            formData.append('file', $('#file')[0].files[0]);
//            console.log($('#file')[0].files[0].size);//文件大小
            upload(_url + "/upload", formData);
        });

        $('#uploads').bind('click', function () {
            var formData = new FormData();
            var files = $('#files')[0];
            if (files.files.length <= 0) {
                return;
            }
            for (i = 0; i < files.files.length; i++) {
                formData.append('files', files.files[i]);
            }
//            console.log($('#file')[0].files[0].size);
            upload(_url + "/uploads", formData);
        });


    });

    function upload(url, formData) {
        $.ajax({
            //提交数据的类型 POST GET
            type: "POST",
            cache: false,
            contentType: false,
            processData: false,
            //提交的网址
            url: url,
            //提交的数据
            data: formData,
            //返回数据的格式
            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
            //在请求之前调用的函数
            beforeSend: function () {
            },
            //成功返回之后调用的函数
            success: function (rs) {
                if (rs) {
                    console.log(rs);
                } else {
                    console.log('error');
                }
            },
            //调用执行后调用的函数
            complete: function () {
            },
            //调用出错执行的函数
            error: function (XMLHttpRequest) {
            }
        });
    }

    /*]]>*/
</script>
</body>
</html>